package com.jackson.engineeringtechnologyguide.springboot.conditional;

/*
 * Author: JacksonCoder
 * FileName: CommonConditionalDemo
 * Version: 1.0.0
 * Date: 2025/1/12
 */

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * SpringBoot 常用内置的条件注解
 */
public class CommonConditionalDemo {

    @Configuration
//    @ConditionalOnProperty(prefix = "condition", value = "engineering", matchIfMissing = false)
    @ConditionalOnProperty(prefix = "condition", name = "engineering", havingValue = "true")
    public class EnableAccountConfiguration {

        // ...

    }

    @Configuration
    @ConditionalOnBean(EnableAccountConfiguration.class)
    public class ImoonConfig {

    }

    @Bean(value = "imoonDataSource")
    @ConditionalOnBean(EnableAccountConfiguration.class)
    public DataSource imoonDataSource() {
        return new HikariDataSource();
    }

}
